package com.minivision.sdktestdemo.ui.view;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.minivision.sdktestdemo.R;
import com.minivision.sdktestdemo.theme.utils.ThemeUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by devtang on 2016/5/13.
 * 音乐的选项列表适配器
 */
public class MusicCtrlPopItemRecyclerAdapter extends RecyclerView.Adapter<MusicCtrlPopItemRecyclerAdapter.PopItemViewHolder> {
    private List<PopClickItemFactory.PopClickItem> mList;

    public MusicCtrlPopItemRecyclerAdapter(List<PopClickItemFactory.PopClickItem> list) {
        mList = list;
    }

    @Override
    public PopItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.pop_ctrl_view_item, parent, false);
        return new PopItemViewHolder(view);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public void onBindViewHolder(PopItemViewHolder holder, int position) {
        PopClickItemFactory.PopClickItem popClickItem = mList.get(position);
        holder.mContent.setText(popClickItem.getmContent());
        holder.mIconView.setImageResource(popClickItem.getmImageId());
        if (popClickItem.getmListener() != null) {
            holder.itemView.setOnClickListener(popClickItem.getmListener());
        }
        ThemeUtils.initTheme(holder.itemView);
    }

    public static class PopItemViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_content)
        TextView mContent;

        @Bind(R.id.img_icon)
        ImageView mIconView;

        public PopItemViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
